
import 'package:dk_flutter_base/dk_core.dart';
import 'package:dk_flutter_base/dk_ui.dart';
import 'package:dk_flutter_module_sale/common/user_track/user_track.dart';
import 'package:dk_flutter_module_sale/phoenix/home/bean/work_home_bean.dart';
import 'package:dk_flutter_module_sale/phoenix/home/widget/work_head_widget.dart';
import 'package:flutter/material.dart';
import '../../../r.dart';
import '../bean/ui_const_bean.dart';
import 'dart:ui';
import 'package:sensors_analytics_flutter_plugin/sensors_analytics_flutter_plugin.dart';

class WorkInformationWidget extends StatelessWidget {

  final ItemsListBean  itemBean;
  WorkInformationWidget(this.itemBean);

  @override
  Widget build(BuildContext context) {
    return _buildedNewWidget(context);
  }

  Widget _buildedNewWidget(BuildContext context) {
    return Container(
      height: UIConstBean.HomeNewItemH,
      color: Colors.transparent,
      padding: const EdgeInsets.only(left: UIConstBean.LRSpace, right: UIConstBean.LRSpace, top: 10),
      child: Card(
        color: Colors.white,
        elevation: 0.0,
        margin: const EdgeInsets.only(bottom: 0),
        clipBehavior: Clip.antiAliasWithSaveLayer,
        shape: const RoundedRectangleBorder(
          side: BorderSide.none,
          borderRadius: BorderRadius.all(Radius.circular(UIConstBean.CircularRadius),
          ),
        ),
        child: Container(
            padding: const EdgeInsets.only(left: UIConstBean.InnerLRSpace,right: UIConstBean.InnerLRSpace,top: UIConstBean.InnerTopSpace),
            color: Colors.white,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                WorkHeadWidget(itemHeadTap: (){
                  print('------点击更多-----');
                  if(itemBean!= null) {
                    Map<String,dynamic> map = Map<String,dynamic>();
                    map["name"] = itemBean.categoryName;
                    if(itemBean.categoryName == "蛋壳资讯") {
                      UserTrack.track("click_main_more_information", map);
                    }
                    RouteUtil.goPage(itemBean.appRouteUrl);
                  }
                } ,title: itemBean.categoryName,indicateType: HomeHeadTitleIndicateType.HomeHeadTitleIndicateLookAtMoreType,),
                SizedBox(height: 24,),
                Container(
                  height: 140,
                  color: Colors.white,
                  padding: const EdgeInsets.only(top: 0),
                  child: GridView(
                    physics: NeverScrollableScrollPhysics(),
                    padding: EdgeInsets.only(top: 0),
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                      crossAxisCount: 2,
                      mainAxisSpacing: 10,
                      crossAxisSpacing: 10,
                    ),
                    children: _buildNewsWidget(),
                  ),
                ),
              ],
            )
        ),
      ),
    );
  }

  List<Widget> _buildNewsWidget() {
    List<Widget> widges = List<Widget>();
    for(AppArticleVosListBean  articleVosListBean in itemBean.appArticleVos) {
      widges.add(_buildGridWidget(articleVosListBean));
    }
    return  widges;
  }

  Widget _buildGridWidget(AppArticleVosListBean  articleVosListBean) {
    String defaultIcon = R.imagesPortalInformationEmptyPng;
    return InkWell(
      onTap: (){
        print('------点击图片-----');
        RouteUtil.goPage(articleVosListBean.appRouteUrl);
      },
      child: Container(
        color: Colors.white,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            CachedNetworkImage(
              imageUrl: articleVosListBean.coverImageUrl,
              placeholderFadeInDuration: Duration(microseconds: 1),
              fadeOutDuration: Duration(microseconds: 1),
              placeholder: (context, url) => Image.asset(defaultIcon),
              errorWidget: (context, url, error) => Image.asset(defaultIcon),
              fit: BoxFit.contain,
              height: 108,
            ),
            SizedBox(height: 12,),
            Text(articleVosListBean.title,
              textAlign: TextAlign.center,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(color: Color(0xff333333),fontSize: 14,fontWeight: FontWeight.normal),
            ),
            Spacer(),
          ],
        ),
      )
    );
  }
}

